#include <iostream>
#include "Hand.h"

Hand::Hand() {
}

void Hand::add(Card *p_Card) {
	cards.push_back(p_Card);
}

void Hand::clear() {
	cards.clear();
}

int Hand::getTotal() const {
		int numberOfAces = 0;
		int result=0;
		int temp=0;
		if(!cards.empty())
		{
			for(int i=0;i<cards.size();++i)
			{
				if((*cards[i]).isVisible() == true) {
					temp = ((Card)(*cards[i])).getPoints();
					if(temp==1 || temp == 11)
					{
						++numberOfAces;
					}
					result+=temp;
				}
			}
			for(int j=0;j<numberOfAces;j++)
			{
				if(result>21)
				{
					result-=10;
				}
			}
		}
		return result;
	}

Card* Hand::getCard(int index) const {
	return cards[index];
}

void Hand::printHandActual() const {
	if(cards[1]->isVisible() == false && this->getTotal() == 21) //If the house has visibility to false, but has 21, set visibility to true 
		this->getCard(1)->setVisibility(true);

	for(int i=0;i<cards.size();++i) {
		std::cout << cards[i]->getRank() <<  cards[i]->getSuit() << " ";
	}
	if(cards[1]->isVisible() == true)
		std::cout << "<" << this->getTotal() << ">";
}

Hand::~Hand()
{
	for(int i=0;i<cards.size();++i)
	{
		delete cards[i];
	}
	cards.clear();
}